package com.retail.file.server.test;

import com.aliyun.oss.OSSClient;

import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class Upload {
    @Resource
    private OSSClient ossClient;

    public void testUpload() throws FileNotFoundException {
        //填写Bucket名称,例如examplebucket
        String bucketName = "xxx";
        //填写Object完整路径,完整路径中不能包含Bucket名称,例如exampled/example
        String objectName = "20230202235006.jpg";

        //填写本地文件的完整路径,例如D:\\localpath\\examplefile.txt
        //如果未指定的本地路径,则默认从示例程序所属项目对应本地路径中上传文件流
        String filePath = "C:\\baidudownloads\\20230202235006.jpg";

        FileInputStream fileInputStream = new FileInputStream(filePath);

        ossClient.putObject(bucketName,objectName,fileInputStream);

        ossClient.shutdown();

        System.out.println("上传完成");
    }
}
